import * as echarts from 'echarts';

// const debounce = function (fn: Function, delay: number) {
//   let timer: any = null;

//   return () => {
//     if (timer) {
//       clearTimeout(timer);
//     }

//     timer = setTimeout(() => {
//       fn.apply(this as any, ...args);
//     }, delay);
//   };
// };

export const initEchart = function (el: HTMLElement) {
  const eChartInstance = echarts.init(el);

  const setOption = (opt: echarts.EChartsOption) => {
    eChartInstance.setOption(opt);
  };

  window.addEventListener('resize', () => {
    console.log(233);
    eChartInstance.resize();
  });

  return {
    eChartInstance,
    setOption,
  };
};
